﻿using System;
using System.Web;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;

using LTJ.Entity;
using LTJ.Common;
using LTJ.Config;
using LTJ.FrameWork;

namespace LTJ.WebPage.SystemManage.route
{
    /// <summary>
    /// 系统管理—线路编辑
    /// </summary>
    public partial class routeedit : AdminPage
    {
        protected string opmode = SASRequest.GetString("opmode");
        protected int rid = SASRequest.GetInt("rid", 0);
        protected RouteBaseInfo rbinfo = new RouteBaseInfo();

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 编辑线路信息
        /// </summary>
        protected void editroute_Click(object sender, EventArgs e)
        {
            rbinfo.loadport = SASRequest.GetString("ajaxloadportdatalist_value");
            rbinfo.tranport = SASRequest.GetString("ajaxtranportdatalist_value");
            rbinfo.destport = SASRequest.GetString("ajaxcorpportdatalist_value");
            rbinfo.routeid = SASRequest.GetInt("ajaxcorproutedatalist_value", 0);
            rbinfo.pier = SASRequest.GetString("ajaxdockdatalist_value");
            rbinfo.range = routerange.Text;
            rbinfo.schbegin = SASRequest.GetString("weekstart_value");
            rbinfo.schend = SASRequest.GetString("weekend_value");
            rbinfo.validbegin = starttime.SelectedDate.ToString();
            rbinfo.validend = endtime.SelectedDate.ToString();
            rbinfo.bio = Utils.RemoveHtml(bio.Text);
            //rbinfo.cid = companyinfo.id;
            rbinfo.uid = userid;

            rbinfo._20GP = _20GPprice.Text;
            rbinfo._40GP = _40GPprice.Text;
            rbinfo._40HQ = _40HQprice.Text;
            rbinfo.YAS = USD_YAS_20GP.Text + "," + USD_YAS_40GP.Text + "," + USD_YAS_40HQ.Text;
            rbinfo.CIC = USD_CIC_20GP.Text + "," + USD_CIC_40GP.Text + "," + USD_CIC_40HQ.Text;
            rbinfo.EBS = USD_EBS_20GP.Text + "," + USD_EBS_40GP.Text + "," + USD_EBS_40HQ.Text;
            rbinfo.PSS = USD_PSS_20GP.Text + "," + USD_PSS_40GP.Text + "," + USD_PSS_40HQ.Text;
            rbinfo.OTHER = USD_OTHER_20GP.Text + "," + USD_OTHER_40GP.Text + "," + USD_OTHER_40HQ.Text;
            rbinfo.CAF = USD_CAF_20GP.Text + "," + USD_CAF_40GP.Text + "," + USD_CAF_40HQ.Text;
            rbinfo.BAF = USD_BAF_20GP.Text + "," + USD_BAF_40GP.Text + "," + USD_BAF_40HQ.Text;
            rbinfo.AMS_ENS = USD_AMS_ENS.Text;
            rbinfo.QFF = RMB_QFF_20GP.Text + "," + RMB_QFF_40GP.Text + "," + RMB_QFF_40HQ.Text;
            rbinfo.DCF = RMB_DCF_20GP.Text + "," + RMB_DCF_40GP.Text + "," + RMB_DCF_40HQ.Text;
            rbinfo.XSF = RMB_XSF_20GP.Text + "," + RMB_XSF_40GP.Text + "," + RMB_XSF_40HQ.Text;
            rbinfo.THC = RMB_THC_20GP.Text + "," + RMB_THC_40GP.Text + "," + RMB_THC_40HQ.Text;
            rbinfo.ECR = RMB_ECR_20GP.Text + "," + RMB_ECR_40GP.Text + "," + RMB_ECR_40HQ.Text;
            rbinfo.RMB_EBS = RMB_EBS_20GP.Text + "," + RMB_EBS_40GP.Text + "," + RMB_EBS_40HQ.Text;
            rbinfo.DOC = RMB_DOC.Text;
            rbinfo.RMB_CIC = RMB_CIC_20GP.Text + "," + RMB_CIC_40GP.Text + "," + RMB_CIC_40HQ.Text;
            rbinfo.isconfim = SASRequest.GetInt("alonecheck", 0);

            if (rbinfo.loadport == "")
            {
                base.RegisterStartupScript("PAGETEMPLATE", "请选择起运港！");
                return;
            }
            if (rbinfo.routeid <= 0)
            {
                base.RegisterStartupScript("PAGETEMPLATE", "请选择授权航线！");
                return;
            }
            if (rbinfo.destport == "")
            {
                base.RegisterStartupScript("PAGETEMPLATE", "请选择目的港！");
                return;
            }
            if (rbinfo.pier == "")
            {
                base.RegisterStartupScript("PAGETEMPLATE", "请选择码头！");
                return;
            }

            if (opmode == "add" || opmode == "copy")
            {
                rbinfo.id = RouteBases.CreateRouteBase(rbinfo);

                if (rbinfo.id <= 0)
                {
                    base.RegisterStartupScript("PAGETEMPLATE", "线路创建失败，请与管理员联系！");
                    return;
                }
            }
            else if (opmode == "edit")
            {
                if (RouteBases.UpdateRouteBase(rbinfo) <= 0)
                {
                    base.RegisterStartupScript("PAGETEMPLATE", "线路更新失败，请与管理员联系！");
                    return;
                }
            }

            base.RegisterStartupScript("PAGE", "parent.document.getElementById('reclick').click();parent.Lightview.hide();");
        }

        private void SetPrice(string valuearray, Control.TextBox tb1, Control.TextBox tb2, Control.TextBox tb3)
        {
            if (!string.IsNullOrEmpty(valuearray) && valuearray.Split(',').Length >= 3)
            {
                tb1.Text = valuearray.Split(',')[0];
                tb2.Text = valuearray.Split(',')[1];
                tb3.Text = valuearray.Split(',')[2];
            }
        }

        #region Web 窗体设计器生成的代码

        override protected void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }

        private void InitializeComponent()
        {
            if (opmode == "edit" || opmode == "copy")
            {
                rbinfo = RouteBases.GetRouteBaseInfo(rid);
                routerange.Text = rbinfo.range;
                starttime.SelectedDate = DateTime.Parse(rbinfo.validbegin);
                endtime.SelectedDate = DateTime.Parse(rbinfo.validend);
                _20GPprice.Text = rbinfo._20GP;
                _40GPprice.Text = rbinfo._40GP;
                _40HQprice.Text = rbinfo._40HQ;

                SetPrice(rbinfo.YAS, USD_YAS_20GP, USD_YAS_40GP, USD_YAS_40HQ);
                SetPrice(rbinfo.CIC, USD_CIC_20GP, USD_CIC_40GP, USD_CIC_40HQ);
                SetPrice(rbinfo.EBS, USD_EBS_20GP, USD_EBS_40GP, USD_EBS_40HQ);
                SetPrice(rbinfo.PSS, USD_PSS_20GP, USD_PSS_40GP, USD_PSS_40HQ);
                SetPrice(rbinfo.OTHER, USD_OTHER_20GP, USD_OTHER_40GP, USD_OTHER_40HQ);
                SetPrice(rbinfo.CAF, USD_CAF_20GP, USD_CAF_40GP, USD_CAF_40HQ);
                SetPrice(rbinfo.BAF, USD_BAF_20GP, USD_BAF_40GP, USD_BAF_40HQ);
                USD_AMS_ENS.Text = rbinfo.AMS_ENS;
                SetPrice(rbinfo.QFF, RMB_QFF_20GP, RMB_QFF_40GP, RMB_QFF_40HQ);
                SetPrice(rbinfo.DCF, RMB_DCF_20GP, RMB_DCF_40GP, RMB_DCF_40HQ);
                SetPrice(rbinfo.XSF, RMB_XSF_20GP, RMB_XSF_40GP, RMB_XSF_40HQ);
                SetPrice(rbinfo.THC, RMB_THC_20GP, RMB_THC_40GP, RMB_THC_40HQ);
                SetPrice(rbinfo.ECR, RMB_ECR_20GP, RMB_ECR_40GP, RMB_ECR_40HQ);
                SetPrice(rbinfo.RMB_EBS, RMB_EBS_20GP, RMB_EBS_40GP, RMB_EBS_40HQ);
                RMB_DOC.Text = rbinfo.DOC;
                SetPrice(rbinfo.RMB_CIC, RMB_CIC_20GP, RMB_CIC_40GP, RMB_CIC_40HQ);
                bio.Text = rbinfo.bio;
            }

            editroute.Click += new EventHandler(editroute_Click);
        }

        #endregion
    }
}